<?php
$loader->requireOnce('ordo/SurgeryParticipant.class.php');
$loader->requireOnce('ordo/SurgeryServiceGroup.class.php');
$loader->requireOnce('ordo/SurgeryTeamTemplate.class.php');
$loader->requireOnce('ordo/Department.class.php');

class C_Surgery extends Controller {

	const SURGERY_TEAM_TEMPLATE_NUM_OF_ITEMS = 7;

	public function C_Surgery($template_mod = "general") {		
		parent::Controller();		
		$this->template_mod = $template_mod;
		$this->view->path 	= 'surgery';
		$this->setLayout('admin');
	}

	public function actionLoadOpenSurgeryAjax(){
		$recordId 	=	$_GET['recordId'];
		$surgery 	= 	ORDataObject::factory('Surgery')->getSurgeryObjectFromRecordId($recordId);

		$surgeryId 	= 	$surgery->get_id();

		$surPart 	= 	ORDataObject::factory('SurgeryParticipant');
		$roleList	=	$surPart->getParticipantRoleList();
		$partList = array();
		if($surgeryId > 0){
			// Get surgery participants of the surgery
			$surParIdList = $surPart->getIdsBySurgeryId($surgeryId);
			foreach ($surParIdList as $key => $id){
				$surPart = Celini::newORDO('SurgeryParticipant', $id);
				$personId = $surPart->getPersonId();
				$name = $surPart->getParticipantName();				
				$partList[$surPart->getRole()][]=array(
				'id'=>$personId, 
				'name'=>$name, 
				'roleName'=> Utils::getEnumTextByKey(EnumerationConstant::SURGERY_PARTICIPANT_ROLE,
				$surPart->getRole()));
			}
		}

		$surgeryServiceId = $surgery->getSurgeryServiceId();

		//Load Surgery Team Template
		$obj = Celini::newORDO('SurgeryTeamTemplate');
		$templateId = SurgeryTeamTemplate::NORMAL_TEMPLATE;
		$templates = $obj->listCommonTemplates($templateId);

		$this->assign('templates', $templates);
		if (sizeof($templates) > 0) {
			$this->assign('firstTemplateId', $templates[0]['template_id']);

		}

		// Push data to the template
		$this->assign('recordId', $recordId);
		$this->assign_by_ref("surgery",$surgery);
		$this->assign_by_ref("surgeryService",$surgery->getSurgeryServiceObject());
		$this->assign_by_ref("participants",$partList);
		$this->assign_by_ref("participantRoles",$roleList);		

		$this->assign("index", 0);
		//@LOCALIZATION
		$currentDate	=	L10nHelper::renderDateTime(date('Y-m-d'));
		$this->assign("currentDate", L10nHelper::getDateParts($currentDate));
		$this->assign("surgeryDate", L10nHelper::getDateParts($surgery->getDate()));
		$this->assign('surgery_service_id', $surgeryServiceId);
		$sv = ORDataObject::factory('SurgeryService');
		$sv->setup($surgeryServiceId);
		$surgeryType = Utils::getEnumTextByKey(EnumerationConstant::SURGERY_TYPE, $sv->get('enum_surgery_type'));
		$this->assign('surgery_service_id_type', $surgeryType);

		$orders	=	L10nHelper::getYMDorder();
		$this->assign('datePart_0', $orders[0]);
		$this->assign('datePart_1', $orders[1]);
		$this->assign('datePart_2', $orders[2]);

		$data4RenderPopUp	=	Celini::newORDO('SurgeryService')->getData4RenderSelectSurgeryService();
		$this->assign('groupList', $data4RenderPopUp['groupList']);
		$this->assign('servList', $data4RenderPopUp['servList']);
		$this->assign('surgeryName', $sv->getSurgeryNameById($surgery->get('surgery_service_id')));
		return $this->view->render("viewSurgery.html");
	}



	function actionAddNewTemplateAjax() {
		// Process serialized form to get array of fields
		$templateId = $_POST['template_id'];

		// Add new template
		$tpl = Celini::newORDO('SurgeryTeamTemplate');

		$info['template_name'] = $_POST['template_name'];
		$info['note'] = $_POST['template_note'];
		// Update info of template, including template_name, note, modified
		$info['template_id'] = $templateId;
		$tpl->updateTemplate($info);

		// Delete all old template items
		$tpl->removeTemplateItems($templateId);
		// Add prescription item to template
		for ($i=0; $i < self::SURGERY_TEAM_TEMPLATE_NUM_OF_ITEMS; $i++){
			$item['template_id'] = $templateId;
			$item['role'] = $_POST['template_role'][$i];
			$item['person_id'] = $_POST['template_employee'][$i];

			$tplItem = Celini::newORDO('SurgeryTeamTemplateItem');
			$tplItem->addNewTemplateItem($item);
		}
		return json_encode(array(
                'templateId'    => $templateId));   

	}

	private function processSerializedForm($serialized){
		$post = explode('&',$serialized);
		$keys = array();
		$vals = array();
		foreach ($post as $item){
			$item = explode('=', $item);
			array_push($keys, $item[0]);
			array_push($vals,$item[1]);
		}
		return array_combine($keys,$vals);
	}

	function actionGetTemplateAjax(){
		$items = Celini::newORDO('SurgeryTeamTemplateItem')->getTemplateItems($_GET['template_id']);
		$template = Celini::newORDO('SurgeryTeamTemplate')->getTemplate($_GET['template_id']);
		$roleList 	= 	ORDataObject::factory('SurgeryParticipant')->getParticipantRoleList();

		$employeeList = array();
		for($i = 0; $i < self::SURGERY_TEAM_TEMPLATE_NUM_OF_ITEMS; $i++) {
			if ( !isset($items[$i]) ){
				$items[$i]['surgery_team_template_item_id'] = '';
				$items[$i]['role'] 	= '';
				$items[$i]['person_id'] 	= '';
				$items[$i]['employeeList']	= array();

			}

			if ($items[$i]['role'] != '') {
				$list = Celini::newORDO('Employee')->getUserList(array($this->mappingRoleToEmployeeType($items[$i]['role'])), true);
				$items[$i]['employeeList']	= $list;

			} else {
				array_push($employeeList, array());
				$items[$i]['employeeList']	= array();

			}
				
		}

		$this->assign('items', $items);
		$this->assign('roleList', $roleList);
		$this->assign('template', $template);
		$this->assign('i', 0);
		$this->assign('stt', 1);
		return $this->view->render('surgery_team_template_item.html');

	}

	public function buildHtmlOptions($list, $selected, $hasNullValue) {
		$res = '';
		if ($hasNullValue) {
			if ($selected == '') {
				$res .= "<option value='' selected='selected'>---</option>";
			} else {
				$res .= "<option value=''>---</option>";
			}
				
		}

		foreach ($list as $key => $value) {
			if ($selected == $key) {
				$res .= "<option value='" . $key . "' selected='selected'>$value</option>";
			} else {
				$res .= "<option value='" . $key . "' >$value</option>";
			}
		}

		return $res;

	}

	public function actionGetEmployeeSuggestionAjax(){
		if(isset($_GET['part']) && $_GET['part']!=''){
			$part = $_GET['part'];
			$response = array();

			$res = Celini::newORDO('Employee')->getEmployeeSuggestion($part);
				
			while($res && !$res->EOF){
				$response[] = $res->fields['name'];
				$res->MoveNext();
			}
			echo json_encode($response);
		}
	}

	public function actionEditSurgeryAjax(){
		$_POST['surgeryDiagnosis']	=	Utils::sanitizeText($_POST['surgeryDiagnosis'],false);
		$_POST['surgicalHappening']	=	Utils::sanitizeText($_POST['surgicalHappening'],false);

		$dates['year']	=	(int)Utils::sanitizeText($_POST['surgeryDate_yyyy']);
		$dates['month']	=	(int)Utils::sanitizeText($_POST['surgeryDate_mm']);
		$dates['day']	=	(int)Utils::sanitizeText($_POST['surgeryDate_dd']);
		$date			=	L10nHelper::getISODate($dates);

		// Store surgery information
		$surgeryId	=	$this->editSurgery($_POST['surgeryId'], $_POST['recordId'], $date, $_POST['surgeryDiagnosis'],
		$_POST['anesthesia'], $_POST['surgicalHappening'],
		$_POST['surgicalMethod'], $_POST['h_surgeryName'], $_POST['description']);

		// Get participants info of the surgery
		$i=0;
		$participant = ORDataObject::factory('SurgeryParticipant');
		$participant->deleteParticipants($surgeryId);

		$personIdList = $_POST['personNames'];
		foreach ($personIdList as $personId) {
			$participant = Celini::newORDO('SurgeryParticipant');
			$participant->setData($surgeryId, $personId, $_POST['roles'][$i]);
			$participant->persist();
				
			$i++;
		}

		return $_POST['recordId'];
	}

	public function editSurgery($surgeryId, $recordId, $surgeryDate='', $surgeryDiagnosis='',
	$anesthesia='', $surgicalHappening='', $surgicalMethod='', $surgeryName='', $description=''){
		if($surgeryId > 0){
			$surgery = Celini::newORDO('Surgery', $surgeryId);
		}
		else{
			$surgery = Celini::newORDO('Surgery')->getSurgeryObjectFromRecordId($recordId);
		}
		$surgery->setData($recordId, $surgeryDate, $surgeryDiagnosis,
		$anesthesia, $surgicalHappening, $surgicalMethod, $surgeryName, $description);
		$surgery->persist();

		$surgeryId	=	$surgery->get_id();
		return $surgeryId;
	}

	public function actionLoadPreviousSurgery($recordId = 0){
		if (isset($_GET['recordId'])) {
			$recordId =	$_GET['recordId'];
		}
		$surgery = ORDataObject::factory('Surgery');
		$surgery = $surgery->getSurgeryObjectFromRecordId($recordId);
		$surgeryId = $surgery->getId();
		if ($surgeryId > 0) {
			$surPart = ORDataObject::factory('SurgeryParticipant');
			$surParIdList = $surPart->getIdsBySurgeryId($surgeryId);
			$roleList = $surPart->getParticipantRoleList();
			$partList = array();
			foreach ($surParIdList as $key => $id){
				$surPart	=	ORDataObject::factory('SurgeryParticipant');
				$surPart->setup($id);

				if(array_key_exists($surPart->getRole(),$partList)){
					// TODO: @LOCALIZATION
					array_push($partList[$surPart->getRole('vi-VN')],$surPart->getParticipantName());
				}
				else{
					// TODO: @LOCALIZATION
					$partList[$surPart->getRole('vi-VN')]=array($surPart->getParticipantName());
				}
			}
			$happening			=	str_replace("\n","<br/>",$surgery->getHappening());
			// Push data to the template
			$this->assign_by_ref("surgery",$surgery);
			$this->assign_by_ref("surgeryService",$surgery->getSurgeryServiceObject());
			$this->assign_by_ref("participants",$partList);
			$this->assign_by_ref("participantRoles",$roleList);
			$this->assign("happening",$happening);
			echo $this->view->render("viewPreviousSurgery.html");
		} else {
			echo "<div class='form_container' style='width: 220px'><span class='label'>" . L10nHelper::_("Don't have surgery info") . "</span></div>";
		}
	}

	public function actionValidateEmployeeAjax(){
		if(isset($_POST['name'])){
			$name = Utils::sanitizeText($_POST['name']);
				
			$res = Celini::newORDO('Employee')->isExistedEmployee($name);
			if($res && !$res->EOF){
				return 'true';
			}
		}
		return 'false';
	}

	public function actionManagement(){
		return $this->view->render('management.html');
	}

	public function actionListInTypeView(){
		$typeList	= Utils::getEnumArrayKey(EnumerationConstant::SURGERY_TYPE);
		$this->assign('typeList', $typeList);
		return $this->view->render('surgery_service_list.html');
	}
	
	public function actionListInGroupView(){
		$superGroups		=	Celini::newORDO('SurgeryServiceGroup')->listSurgeryServiceGroup();
		$subGroups			=	array();
		$count				=	0;
		foreach($superGroups as $superGroup){
			$catergory			=	$superGroup['group_id'];
			$subGroups[$count]	=	array(
				'div'		=>	$catergory.'_div',
				'select'	=>	$catergory.'_select',
				'group'		=>	Celini::newORDO('SurgeryServiceGroup')->listSurgeryServiceGroup($catergory),
				'elem_div'	=>	$catergory.'_elem_div',
				'elem_select'=>	$catergory.'_elem_select'
			);
			$count++;
		}
		$this->assign('superGroups', $superGroups);
		$this->assign('subGroups', $subGroups);
		$this->assign('allowanceClass', Utils::getEnumArrayKey(EnumerationConstant::SURGERY_SERVICE_ALLOWANCE_CLASS));
		return $this->view->render('surgery_service_group_list.html');
	}

	public function actionListNewSurgeryService2Add(){
		$deptList = Celini::newORDO('Department')->listAll();
		$superGroups		=	Celini::newORDO('SurgeryServiceGroup')->listSurgeryServiceGroup();
		$subGroups			=	array();
		$count				=	0;
		foreach($superGroups as $superGroup){
			$catergory			=	$superGroup['group_id'];
			$subGroups[$count]	=	array(
				'div'		=>	$catergory.'_div',
				'select'	=>	$catergory.'_select',
				'group'		=>	Celini::newORDO('SurgeryServiceGroup')->listSurgeryServiceGroup($catergory),
				'elem_div'	=>	$catergory.'_elem_div',
				'elem_select'=>	$catergory.'_elem_select'
			);
			$count++;
		}
		$this->assign('superGroups', $superGroups);
		$this->assign('subGroups', $subGroups);
		$this->assign('allowanceClass', Utils::getEnumArrayKey(EnumerationConstant::SURGERY_SERVICE_ALLOWANCE_CLASS));
		$this->assign('typeList', Utils::getEnumArrayKey(EnumerationConstant::SURGERY_TYPE));
		$this->assign('deptList', $deptList);
		return $this->view->render('service_list.html');
	}

	public function actionListSurgeryServiceInTypeAjax() {
		$type		=	$_GET['type'];
		$servList	=	Celini::newORDO('SurgeryService')->listSurgeryServicesInTypeView($type);
		return json_encode($this->rederSurgeryServiceListInType($servList));
	}
	
	public function actionListSurgeryServiceInGroupAjax(){
		$groupId	=	$_GET['group_id'];
		if($groupId !== NULL){
			$servList	=	Celini::newORDO('SurgeryService')->listSurgeryServicesInGroupView($groupId);
			return json_encode($this->rederSurgeryServiceListInGroup($servList, $groupId));
		}
		else{
			return 'error';
		}
	}

	public function actionListServiceByDepartmentAjax() {
		$departmentId	=	$_GET['department_id'];
		if ($departmentId == 'all') {
			$departmentId = false;
		}
		$servList = Celini::newORDO('Service')->getNotSurgeryServiceInfo($departmentId, 0);
		return json_encode($this->renderServiceList($servList));
	}

	private function renderSurgeryServiceList($servList) {
		$sr = Celini::newORDO('ServiceRoom');
		$body = "";
		$count = 1;
		foreach ($servList as $row) {
			$aRow = "";
			$room = "";
				
			$id = $row['service_id'];
			$res = $sr->getRoomsOfService($id);
			foreach ($res as $roomName) {
				$room .= $roomName['name'] . ", ";
			}
				
			if (strlen($room) > 0) {
				$room = substr($room, 0, strlen($room) - 2);
			}
				
			$payment = L10nHelper::_("Postpaid");
			if ($row['payment_type'] == Service::BEFORE) {
				$payment = L10nHelper::_("Prepaid");
			}
				
			$aRow	.=	"<tr id='$id'>";
			$aRow	.=	"<td><span class='order'>$count</span></td>";
			$aRow	.=	"<td><span class='remark'>".$row['name'] . "</span></td>";
			$aRow	.=	"<td>$room</td>";
			if(strtolower($row['surgery_type'])=='small'){
				$aRow .= "<td>" . L10nHelper::_("Small surgery") . "</td>";
			}
			elseif(strtolower($row['surgery_type'])=='medium'){
				$aRow .= "<td>" . L10nHelper::_("Medium sugery") . "</td>";
			}
			elseif(strtolower($row['surgery_type'])=='big'){
				$aRow .= "<td>" . L10nHelper::_("Big surgery") . "</td>";
			}
			else{
				$aRow .="<td>&nbsp;</td>";
			}
			$aRow	.= "<td>".$row['allowance_class']."</td>";
			$aRow	.=	"<td>" . L10nHelper::renderCurrency($row['price']) . "</td>";
			$aRow	.=	"<td>" . L10nHelper::renderCurrency($row['patient_required_insurance_price']) . "</td>";
			$aRow	.=	"<td>" . L10nHelper::renderCurrency($row['patient_volunteered_insurance_price']) . "</td>";
			$aRow	.=	"<td>" . $payment . "</td>";
			if ($row['disabled'] == 0) {
				$aRow .= "<td><span>" . L10nHelper::_("In Use_1") . "</span></td>";
				$aRow .= "<td><a class='btn' href='javascript:lockService($id);' title='" . L10nHelper::_("Service temporary locked") . "'>"
				. "<img src='../images/lock_small.png' alt='" . L10nHelper::_("Lock") . "'></img>"
				. "</a></td>";
			} else if ($row['disabled'] == 1) {
				$aRow .= "<td><span class='impression'>" . L10nHelper::_("Lock") . '</span></td>';
				$aRow .= "<td><a class='btn' href='javascript:unlockService($id);' title='" . L10nHelper::_("Reuse service") . "'>"
				. "<img src='../images/unlock_small.png' alt='" . L10nHelper::_("Reuse") . "'></img>"
				. "</a></td>";
			}
			$aRow .= "</tr>";
			$body .= $aRow;
			$count++;
		}
		return array('body' => $body, 'total' => --$count);
	}

	private function rederSurgeryServiceListInType($servList){
		$body	=	"";
		$count	=	1;

		$typeList	=	Utils::getEnumArrayKey(EnumerationConstant::SURGERY_TYPE);
		$optionList	=	"<option value='1' label=". $typeList['1']."'>".$typeList['1']."</option>";
		$optionList	.=	"<option value='2' label=". $typeList['2']."'>".$typeList['2']."</option>";
		$optionList	.=	"<option value='3' label=". $typeList['3']."'>".$typeList['3']."</option>";
		
		foreach($servList as $row){
			$aRow	=	"";
				
			$id		=	$row['service_id'];
			$aRow	.=	"<tr id='$id'>";
			$aRow	.=	"<td><span class='order'>$count</span></td>";
			$aRow	.=	"<td><span class='remark'>".$row['name'] . "</span></td>";
			$aRow	.=	"<td><span id='$id"."_type'>".Utils::getEnumTextByKey(EnumerationConstant::SURGERY_TYPE, $row['type']);
			$aRow	.=		"</span>";
			$aRow	.=	"<select style='display:none' id='".$id."_type_select'>";
			$aRow	.=	$optionList;
			$aRow	.=	"</select></td>";
			$aRow	.=	"<td><a class='btn' href='javascript:editSurgeryServiceType($id)' title='".L10nHelper::_('Edit')."'>";
			$aRow	.=			"<img src='../images/msg_edit.png' style='width:24px;height:24px' alt='".L10nHelper::_('Edit')."'></img>";
			$aRow	.=		"</a>";
			$aRow	.=	"</td>";
			$aRow	.=	"</tr>";
			$body	.=	$aRow;
			$count++;
		}
		return array('body' => $body, 'total' => --$count);
	}
	
	private function rederSurgeryServiceListInGroup($servList, $groupId){
		$body	=	"";
		$count	=	1;
		// Get information about group which the service list belongs to:
		$group	=	Celini::newORDO('SurgeryServiceGroup',$groupId);
		$category =	$group->get('parent_id');
		
		// Render list of services
		foreach($servList as $row){
			$aRow			=	"";			
			$id				=	$row['service_id'];
			$allowanceClass	=	Utils::getEnumValue(EnumerationConstant::SURGERY_SERVICE_ALLOWANCE_CLASS, $row['allowance_class']);
			$allowance		=	$row['allowance'];
			$argumentList	=	"\"$id\",\"".$row['name']."\",".$category.", $groupId, \"".$row['allowance_class']."\", \"".$row['allowance']."\"";
			
			$aRow	.=	"<tr id='$id'>";
			$aRow	.=	"<td><span class='order'>$count</span></td>";
			$aRow	.=	"<td><span class='remark'>" . $row['name'] . "</span></td>";
			$aRow	.=	"<td style='text-align:center'>";
			if($allowanceClass == EnumerationConstant::SURGERY_SERVICE_ALLOWANCE_SPECIAL_CLASS){
				$aRow .= $allowance; 
			}
			$aRow	.= "</td>";
			$aRow	.=	"<td style='text-align:center'>";
			if($allowanceClass == EnumerationConstant::SURGERY_SERVICE_ALLOWANCE_CLASS_1){
				$aRow .= $allowance; 
			}
			$aRow	.= "</td>";
			$aRow	.=	"<td>";
			if($allowanceClass == EnumerationConstant::SURGERY_SERVICE_ALLOWANCE_CLASS_2){
				$aRow .= $allowance; 
			}
			$aRow	.= "</td>";
			$aRow	.=	"<td>";
			if($allowanceClass == EnumerationConstant::SURGERY_SERVICE_ALLOWANCE_CLASS_3){
				$aRow .= $allowance; 
			}
			$aRow	.= "</td>";
			$aRow	.=	"<td><a class='btn' href='javascript:popUpEditGroup(".$argumentList.")' title='".L10nHelper::_('Edit')."'>";
			$aRow	.=			"<img src='../images/msg_edit.png' style='width:24px;height:24px' alt='".L10nHelper::_('Edit')."'></img>";
			$aRow	.=		"</a>";
			$aRow	.=	"</td>";
			$aRow	.=	"</tr>";
			
			$body	.=	$aRow;
			$count++;
		}
		return array('body' => $body, 'total' => --$count);
	}

	private function renderServiceList($servList) {
		$body = "";
		$count = 1;
		
		$typeList	=	Utils::getEnumArrayKey(EnumerationConstant::SURGERY_TYPE);
		$optionList	=	"<option value='1' label=". $typeList['1']."'>".$typeList['1']."</option>";
		$optionList	.=	"<option value='2' label=". $typeList['2']."'>".$typeList['2']."</option>";
		$optionList	.=	"<option value='3' label=". $typeList['3']."'>".$typeList['3']."</option>";
		
		foreach ($servList as $row) {
			$aRow = "";			
			$id = $row['service_id'];
			$argumentList	=	"$id,\"".$row['name']."\"";	
				
			$aRow	.=	"<tr id='$id'>";
			$aRow	.=	"<td><span class='order'>$count</span></td>";
			$aRow	.=	"<td><span class='remark'>".$row['name'] . "</span></td>";			
			
			$aRow	.= "<td><a class='btn' id='".$id."_detail' href='javascript:popUpAddService(". $argumentList .")' title='".L10nHelper::_('Edit detail and save')."'>";
			$aRow	.=			"<img src='../images/view_detail_32x32.png' style='width:24px;height:24px' alt='".L10nHelper::_('Edit detail and save')."'></img>";
			$aRow	.=		"</a>";
			$aRow	.=	"</td>";
			
			$aRow .= "</tr>";
			$body .= $aRow;
			$count++;
		}
		return array('body' => $body, 'total' => --$count);
	}
	
	public function actionSaveSurgeryServiceTypeAjax(){
		$service_id		=	$_POST['service_id'];
		$surgery_type	=	$_POST['type'];
		Celini::newORDO('SurgeryService')->editSurgeryServiceType($service_id, $surgery_type);
		return json_encode(Utils::getEnumTextByKey(EnumerationConstant::SURGERY_TYPE, $surgery_type));
	}
	
	public function actionSaveChangeSurgeryServiceAjax(){
		$surgery2Change	=	array(
			'service_id'	=>	$_POST['service_id'],
			'group_id'		=>	$_POST['group_id'],
			'allowance_class'=>	$_POST['allowance_class'],
			'allowance'		=>	$_POST['allowance']
			);
		Celini::newORDO('SurgeryService')->editSurgeryServiceGroup($surgery2Change);
	}

	public function actionSaveSurgeryServiceAjax(){
		$response	=	'';
		$i = 0;$response['length']=0;
		$surService	=	ORDataObject::factory('SurgeryService');
		while(isset($_POST['services'][$i])){
			$serviceId		=	$_POST['services'][$i];
			$serviceType	=	$serviceId."_type";
			$serviceClass	=	$serviceId."_class";
			if(isset($_POST[$serviceType])){
				$surService->setData($_POST['services'][$i],$_POST[$serviceType], $_POST[$serviceClass]);
				$surService->persist();
			}
			$i++;$response['length']++;
		}

		$response['saved']=1;
		return json_encode($response);
	}
	
	public function actionSaveNewSurgeryServiceAjax(){
		$data2Save	=	array(
			'service_id'	=>	$_POST['service_id'],
			'group_id'		=>	$_POST['group_id'],
			'type'			=>	$_POST['type_key'],
			'allowance_class'=>	$_POST['allowance_class'],
			'allowance'		=>	$_POST['allowance']
		);
		Celini::newORDO('SurgeryService')->saveNewSurgeryService($data2Save);
	}

	function mappingRoleToEmployeeType($role) {
		$employeeTypeId = 0;
		$roleValue = Utils::getEnumValue(EnumerationConstant::SURGERY_PARTICIPANT_ROLE,
		$role);
		switch ($roleValue) {
			case EnumerationConstant::SURGERY_PARTICIPANT_ROLE_SUR:
			case EnumerationConstant::SURGERY_PARTICIPANT_ROLE_ANE:
			case EnumerationConstant::SURGERY_PARTICIPANT_ROLE_INP:
			case EnumerationConstant::SURGERY_PARTICIPANT_ROLE_OBS:
				$employeeTypeId = 1;
				break;
					
			case EnumerationConstant::SURGERY_PARTICIPANT_ROLE_NUR:
				$employeeTypeId = 2;
				break;
					
			case EnumerationConstant::SURGERY_PARTICIPANT_ROLE_TEC:
				$employeeTypeId = 3;
				break;
					
			case EnumerationConstant::SURGERY_PARTICIPANT_ROLE_INT:
				$employeeTypeId = 6;
				break;

		}
			
		return $employeeTypeId;

	}

	public function actionGetUserByEmployeeTypeAjax(){
		if(!isset($_GET['employee_type_id']) || $_GET['employee_type_id'] =='' ) return;
		$employeeTypeId = $this->mappingRoleToEmployeeType($_GET['employee_type_id']);
			
		$employee_list = Celini::newORDO('Employee')->getUserList(array($employeeTypeId));
		$response = '';
		if(isset($employee_list) && $employee_list != ''){
			foreach($employee_list as $employee){
				$response .= "<option value='{$employee['person_id']}' >{$employee['name']}</option>";
			}
		}
		return $response;
	}

}
?>
